#include "formsqlconnect.h"
#include "ui_formsqlconnect.h"
#include <QSqlDatabase>
#include<QDebug>
#include<QSqlQuery>
#include<QMessageBox>
#include<QLineEdit>
#include<QString>
Formsqlconnect::Formsqlconnect(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Formsqlconnect)
{
    ui->setupUi(this);
}

Formsqlconnect::~Formsqlconnect()
{
    delete ui;
}

void Formsqlconnect::on_pushButtonStartconnect_clicked()
{
       QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
       QString servername1 = ui->lineEditServer->text();
       QString servername2 = ui->lineEditPassword->text();
       QString servername3 = ui->lineEditLoginname->text();
       QString servername4 = ui->lineEditDatabasename->text();
       db.setHostName(servername1);
       db.setPassword(servername2);
       db.setUserName(servername3);
       db.setDatabaseName(servername4);
if (db.open())
{
    QMessageBox::information(this, "连接成功", "连接成功");
}
else
{
    QMessageBox::information(this, "连接失败", "连接失败");
}
this->close();
}


void Formsqlconnect::on_pushButtonStopconnect_clicked()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.close();
QMessageBox::information(this, "数据库已断开", "数据库已断开");
}

